library(plyr);library(dplyr)
library(tidyr)
library(ggplot2)
library(lmtest); library(multiwayvcov)#for clustered se's
library(stargazer)
library(stringr)

rm(list=ls())
Num = function(x){as.numeric(as.character(x))}
s = function(x){summary(factor(x))}

#set working directory
#setwd('')
A = read.csv('../data/6-27-17_supermerge_wleaderfrac_deid_trimmed.csv', sep = ';') 

source('repl_6-9-17 cleaning and pca.R') #pca and variable cleaning. Table B1, Figure B1
source('6-14-17 alt pca.R') #alternate version of pca
source('18aug24 neighborhood.R') #add neigh soc dens to main dataframe; summary stats
source('repl_2-07-20_histo.R') #histograms (figures D1, D2)
source('18aug24 baltab.R') #balance table (C1)
source('7sep24 basic list.R') # list experiment (Table 3)
source('repl_6-14-17 inde conn list_11-5-18.R') #main result for individual clientelism (table 4, table F1)
source('repl_6-14-17 marginal effects.R') #marginal effects plot (A1)
source('6-27-17 neigh other list.R') #**Make Neigh dataframe (caste composition etc).
source('28aug24 inde conn list_plus.R') #Table G1
source('replication_networkgraphs_17aug2024.R') #Figure 2

#TABLE 2
#summary(factor(A$ListOut))
#0    1    2    3    4 
#588 3078 2689  735  146 
#summary(factor(A$ListOut[which(A$ListControl == T)]))
#0    1    2    3 
#202 1085  844  273 
#summary(factor(A$ListOut[which(A$ListFavor == T)]))
#0    1    2    3    4 
#202 1010  942  232   72   
#sum(A$ListControl == T) #2404
#sum(A$ListFavor == T) #2458

#check ceiling/floor
#(273 / sum(A$ListControl == T)) # 0.1135607 proportion that might be affected by ceiling
#202 / sum(A$ListControl == T) # 0.08402662 proportion that might be affected by ceiling
################################################################################################################